<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form" :inline="true" :model="form" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="用户电话">
              <el-input v-model="form.username"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="推荐人电话">
              <el-input v-model="form.serversname"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="身份证号">
              <el-input v-model="form.identify"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="处理状态">
              <el-select placeholder="请选择" v-model="form.status">
                <el-option
                  v-for="item in statusOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div class="listDiv" v-loading="tableLoading">
      <!-- table列表 -->
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="identify" label="身份证号"></el-table-column>
        <el-table-column prop="realname" label="用户姓名"></el-table-column>
        <el-table-column prop="username1" label="用户电话1">
          <template slot-scope="scope">
            <div>{{scope.row.username1 | phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column label="推荐人1信息">
          <template slot-scope="scope">
            <div>{{scope.row.serversRealname1}}</div>
            <div>{{scope.row.serversUsername1| phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="username2" label="用户电话2">
          <template slot-scope="scope">
            <div>{{scope.row.username2 | phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="serversRefereeTime1" label="推荐人1绑定时间"></el-table-column>
        <el-table-column label="推荐人2信息">
          <template slot-scope="scope">
            <div>{{scope.row.serversRealname2}}</div>
            <div>{{scope.row.serversUsername2}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="serversRefereeTime2" label="推荐人2绑定时间"></el-table-column>
        <el-table-column prop="type" label="异常类型">
          <template slot-scope="scope">
            <div>{{scope.row.type | typeFn}}</div>
          </template>
        </el-table-column>
        <el-table-column label="处理状态">
          <template slot-scope="scope">
            <div>{{scope.row.status | statusFn}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="orderId" label="单号"></el-table-column>
        <el-table-column prop="remark" label="备注"></el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="100"
          v-if="hasPermission('AdminProjectAbnormalProvider.handleProjectAbnormal')"
        >
          <template slot-scope="scope" v-if="scope.row.status != 1">
            <el-button type="text" size="small" @click="dealWithFn(scope.row.id)">处理</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 处理弹窗 -->
      <el-dialog title="异常处理" :visible.sync="dialog" :before-close="dealWithClose" width="468px">
        <!-- 输入框 -->
        <el-form :inline="true" label-width="80px" label-position="right">
          <el-form-item label="备注">
            <el-input v-model="dealWithForm.remark"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dealWithClose()">取 消</el-button>
          <el-button type="primary" @click="dealWithSubmit()">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="listForm.pageNum"
            :page-sizes="page_sizes"
            :page-size="listForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
          ></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { projectAbnormalList, handleProjectAbnormal } from "@/api/abnormal";

export default {
  name: "abnormalUser",
  data() {
    return {
      val: "1",
      dialog: false,
      dates: "",
      tableLoading: true,
      form: {
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      roleOptions: [],
      page_sizes: [10, 30, 50, 100],
      page_totals: 60,
      listForm: {
        pageNum: 1,
        pageSize: 10
      },
      statusOptions: [
        {
          value: 0,
          label: "未处理"
        },
        {
          value: 1,
          label: "已处理"
        }
      ],
      dealWithForm: {
        id: null,
        remark: ""
      }
    };
  },
  filters: {
    cardType: function(e) {
      return window.helper.cardType(String(e));
    },
    typeFn(e) {
      switch (e) {
        case 0:
          return "未知";
        case 1:
          return "流水单";
        case 2:
          return "补贴单";
        default:
          return "暂无";
      }
    },
    statusFn(e) {
      switch (e) {
        case 0:
          return "未处理";
        case 1:
          return "已处理";
        default:
          return "暂无";
      }
    }
  },
  inject: ["reload"],
  mounted() {
    this.getList(this.listForm);
    this.roleOptions = window.helper.roleFn("listReturn");
  },
  methods: {
    //按钮权限
    hasPermission(e) {
      return window.helper.hasPermission(e);
    },
    //处理按钮
    dealWithFn(e) {
      this.dialog = true;
      this.dealWithForm.id = e;
      // console.log(e)
    },
    // 处理关闭按钮
    dealWithClose() {
      this.dialog = false;
    },
    //处理提交方法
    dealWithSubmit() {
      let datas = this.dealWithForm;
      handleProjectAbnormal(datas)
        .then(res => {
          // console.log(res)
          if (!res.data.code) {
            this.succStatus("处理");
          } else {
            this.$message.error(res.data.msg);
          }
          this.reload();
        })
        .catch(error => {
          this.$message.error(error);
          this.reload();
        });
      this.dialog = false;
    },
    //成功状态弹窗
    succStatus(txt) {
      this.$message({
        message: txt + "成功",
        type: "success"
      });
    },
    //失败状态弹窗
    errorStatus(txt) {
      this.$message.error(txt + "失败");
    },
    //查询
    searchFn() {
      this.form.pageNum = 1;
      // console.log(this.form)
      this.getList(this.form);
    },
    //列表数据获取
    getList(e) {
      this.tableLoading = true;
      let datas = e;
      projectAbnormalList(datas)
        .then(res => {
          if (!res.data.code) {
            // console.log(res)
            this.tableData = res.data.data.list;
            this.page_totals = res.data.data.count;
          } else {
            this.$message.error(res.data.msg);
          }
          this.tableLoading = false;
        })
        .catch(error => {
          this.$message.error(error);
        });
    },
    //改变页面条数
    handleSizeChange(val) {
      this.form.pageSize = val;
      this.getList(this.form);
    },
    //选择页数
    handleCurrentChange(val) {
      this.form.pageNum = val;
      this.getList(this.form);
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
</style>
